<template>
  <el-row :gutter="20" class="title-row">
    <el-button class="fl" @click="handleBack">返回</el-button>
    <el-col :span="12">
      任务名称：
      <span>{{ row.name }}</span>
    </el-col>
    <div
      class="fr"
      v-if="parentRow.progress >= 0 && row.taskState !== 2 && parentRow.evalMode !== 2"
    >
      <el-button @click="handleAddMore">追加项</el-button>
      <el-button @click="handleSubmit('save')">保存</el-button>
      <el-button type="primary" @click="handleSubmit('submit')">提交</el-button>
    </div>
    <div class="fr mr20">
      奖惩总金额：
      <span>{{ mdl.itemMoney }}</span>元
      加减总分：
      <span>{{ mdl.rewardValueSum }}</span>分
    </div>
  </el-row>
</template>

<script>
import { evalUpdate } from '@/api/eval'
import { openNotification, removeSession, getSession } from '@/utils/util'

export default {
  data() {
    return {
      mdl: {},
      row: this.$route.params.row || getSession('startTestRow'),
      type: this.$route.params.type || getSession('startTestType'),
      parentRow: getSession('evalListRow')
    }
  },
  methods: {
    show(obj) {
      console.log('title obj', obj)
      this.mdl = Object.assign({}, obj)
    },
    handleBack() {
      this.$router.push({ name: 'evaluateTable' })
      removeSession('startTestRow')
      removeSession('startTestType')
      removeSession('evalDetailedId')
    },
    handleAddMore() {
      // targetMode 1 科室 3个人
      this.$emit('showTemplate', this.row.targetMode)
    },
    handleSave() {
      console.log('save')
      this.$router.push({
        name: 'evaluateAdditional'
      })
    },
    async handleSubmit(type) {
      const state = type === 'save' ? 1 : 2
      const mes = type === 'save' ? '保存操作成功' : '提交操作成功'
      let param = { state, evalDetailedId: this.mdl.evalDetailedId }
      const res = await evalUpdate(param)
      if (res.state === '000000') {
        openNotification('success', mes)
        removeSession('startTestRow')
        removeSession('startTestType')
        removeSession('evalDetailedId')
        this.$router.push({
          name: 'evaluateTable'
        })
      }
    }
  },
  created() {
    console.log('parentRow', this.parentRow)
  }
}
</script>

<style scoped>
.title-row {
  line-height: 36px;
}
</style>
